<template>
  <div class="bh-mb-16">
    <template v-for="(item, index) in toolbar">
      <bh-button :type="[index === 0 ? 'primary':'default']" v-bind:key="index" @click.native="buttonOption(item)" :disabled="computeDisabled(item)">{{item.title}}</bh-button>
    </template>
  </div>
</template>

<script>
import { BhButton } from 'bh-vue'
import { runTask } from './operation'

export default {
  props: {
    toolbar: Array,
    tableRecord: Number,
    formUrl: String,
    table: Array,
    time: Number,
    queryPath: Object,
    gridAlias: String,
    tableManageNo: Number,
    defKey: String,
    taskid: String
  },
  data () {
    return {

    }
  },
  computed: {
    computeDisabled() {
      return function(item) {
        let value = false;
        if(this.tableRecord === 1 && (item.selectType === 1 || item.selectType === 2)){
          value = false
        }else if(this.tableRecord > 1 && item.selectType === 2){
          value = false
        }else if(item.selectType !== 0){
          value = true
        }
        //manage的类型变为int，如果不存在则默认为0，$$manage <= manage 时 操作时不能选择，options中的不显示
        item.manage = item.manage || 0
        if(this.tableManageNo && (this.tableManageNo <= item.manage)){
          value = true
        }
        if(item.verify && item.verify.___taskStatus === 1){
          value = true
        }
        return value
      }
    }
  },
  methods: {
    //操作按钮功能
    buttonOption(item) {
      runTask(this.$parent, item)
    }
  },
  components: {
    /* eslint-disable-next-line */
    BhButton
  }
}
</script>
